1. Field of the Invention
The invention relates to method for determining size of a buffer, and in particular to size of a buffer in an embedded system.
2. Description of the Related Art
Recently, with increased popularity of embedded systems, devices therein, such as CPUs, bridges, and media access controllers (MAC) may share with the same bus, although only one can access data therethrough at a given time. Thus, an arbiter must obtain authority to utilize the bus based on arbitration rules such as polling or priority. When a device in the embedded system attempts to utilize the bus, a request signal is sent to the arbiter to request bus use. The arbiter chooses one requesting device according to the arbitration rules, the priority of each requesting device, and current status of the bus. Once a device is chosen, the arbiter returns a grant signal thereto. After receiving the grant signal, the chosen device utilizes the bus, for example, accessing data therethrough. Other requesting devices await a grant signal in turn.
Some devices in the embedded system, such as a MAC controller in a network chip, require continuous data transmission. For example, for an Ethernet MAC controller, an entire packet must be transmitted to, for example, a physical layer, continuously. A buffer is usually configured in the device to store the temporary data for transmission. The data in the buffer for a packet must be kept on transmitting. If the size of the buffer in the device is not large enough and the buffer may not be efficiently refilled with subsequent data before the buffer empties, clearance of the buffer causes transmission discontinuity to the media and results in corrupting the packet which must be retransmitted. Also, clearance of the buffer is a condition known as buffer under-run. If buffer under-run occurs frequently, system performance is compromised.
FIG. 1 is a flowchart of a method for operating a conventional MAC controller. When the MAC controller attempts to transmit a packet, a request signal is first sent to the arbiter to request bus ownership. After the MAC controller acquires bus authority, data in the bus is stored into its buffer. After the buffer is fully filled, the MAC controller releases bus authority and keeps on transmitting the data to media. If the buffer is not large enough to store an entire packet, the remaining part of the packet from the bus refills the buffer before it empties. The buffer may empty before refilling, and result in generating buffer under-run so that the entire packet needs re-transmission.
To avoid buffer under-run, an entire packet can be buffered at once. Thus, the size of the buffer in the device is the same as the maximum packet size (MPS) based on the specification. For example, when the maximum packet size of a Ethernet MAC controller is equal to 1536 bytes, the size of the buffer in each Ethernet MAC controller is equal to 1536 bytes. Accordingly, four corresponding buffers, each having a size of 1536 bytes are implemented in four MAC controllers respectively for a specific application. Therefore, manufacturing costs are significant increased.